<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>    
<%@ page import="org.swim.entity.User" %>
<%@ page import="org.swim.entity.HelpRequests" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Help Requests</title>
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
	<%@ include file="NavBar.jsp" %>
	<% 
	boolean areThereReceivedSuspendedHelpRequests = (Boolean) request.getAttribute("areThereReceivedSuspendedHelpRequests");
	boolean areThereReceivedApprovedHelpRequests = (Boolean) request.getAttribute("areThereReceivedApprovedHelpRequests");
	boolean areThereReceivedCompletedHelpRequests = (Boolean) request.getAttribute("areThereReceivedCompletedHelpRequests");
	boolean areThereSentApprovedHelpRequests = (Boolean) request.getAttribute("areThereSentApprovedHelpRequests");
	boolean areThereSentSuspendedHelpRequests = (Boolean) request.getAttribute("areThereSentSuspendedHelpRequests");

	User user = (User) session.getAttribute("user"); %>
	<div class="container">
	<% if(session.getAttribute("status").equals("guest")) { %>
	<%@ include file="NoRights.jsp" %>		
	<%} else { %>
		<h1>Help Requests</h1>
		<div class="container">
			<h2>Received Help Requests</h2>
			<h3>Pending</h3>
			<% if (areThereReceivedSuspendedHelpRequests) { 
				List<HelpRequests> helpRequests = (List<HelpRequests>) request.getAttribute("receivedSuspendedHelpRequests");  
				for (HelpRequests current: helpRequests) { %>
				<div class="row">
					<div class="span4">
						<div class="media"><a class="pull-left" href="<% out.print("Profile?id="+ current.getMittente().getId());%>">
							<img class="media-object" alt="64x64" style="width: 64px; height: 64px;" src="<% out.print(current.getMittente().getAvatar()); %>" data-src="holder.js/64x64">
							<div class="media-body">		
						    <h4 class="media-heading"><% out.print(current.getMittente().getNome() + " " + current.getMittente().getCognome()); %></h4>	
						    </div></a><br />
					    </div>
					       	<p><strong>Ability: </strong><% out.print(current.getAbilita().getNome()); %></p>
					    	<p><strong>Sent: </strong><% out.print(current.getDataInvio()); %></p>
				    </div>
				    <div class="span4">
					    <p>
						 	<a href="ApproveHelpRequest?id=<% out.print(current.getIdRichiesta()); %>"><button class="btn btn-small btn-success" type="button">Approve</button></a>
						  	<a href="DenyHelpRequest?id=<% out.print(current.getIdRichiesta()); %>"><button class="btn btn-small btn-danger" type="button">Deny</button></a>
						</p>
					</div>
			    </div>
		    <% } %>
		    <% } else { %>	
		    	<div class="alert alert-info"><strong>No received help requests:</strong> there are no received help requests to approve</div>
		    <% } %>	
	    	<h3>Approved</h3>
	   		<% if (areThereReceivedApprovedHelpRequests) { 
				List<HelpRequests> helpRequests = (List<HelpRequests>) request.getAttribute("receivedApprovedHelpRequests");  
				for (HelpRequests current: helpRequests) { %>
				<div class="row">
						<div class="span4">
						<div class="media"><a class="pull-left" href="<% out.print("Profile?id="+ current.getMittente().getId());%>">
							<img class="media-object" alt="64x64" style="width: 64px; height: 64px;" src="<% out.print(current.getMittente().getAvatar()); %>" data-src="holder.js/64x64">
							<div class="media-body">		
						    <h4 class="media-heading"><% out.print(current.getMittente().getNome() + " " + current.getMittente().getCognome()); %></h4>	
						    </div></a><br />
					    </div>
					       	<p><strong>Ability: </strong><% out.print(current.getAbilita().getNome()); %></p>
					    	<p><strong>Sent: </strong><% out.print(current.getDataInvio()); %></p>
					    	<p><strong>Approved: </strong><% out.print(current.getDataAccettazione()); %></p>
				   	</div>
					<% if (!current.isCompletata()) { %>
				    <div class="span4">
					    <p>
						 	<a href="DeleteHelpRequest?id=<% out.print(current.getIdRichiesta()); %>"><button class="btn btn-small btn-danger" type="button">Delete</button></a>
						</p>
					</div>
					<% } %>
			</div>
			<% } %>		
		    <% } else { %>	
		    	<div class="alert alert-info"><strong>No received approved requests:</strong> there are no received requests already approved</div>
		    <% } %> 						 
			<h3>Completed</h3>
	   		<% if (areThereReceivedCompletedHelpRequests) { 
				List<HelpRequests> helpRequests = (List<HelpRequests>) request.getAttribute("receivedCompletedHelpRequests");  
				for (HelpRequests current: helpRequests) { %>
				<div class="row">
						<div class="span4">
						<div class="media"><a class="pull-left" href="<% out.print("Profile?id="+ current.getMittente().getId());%>">
							<img class="media-object" alt="64x64" style="width: 64px; height: 64px;" src="<% out.print(current.getMittente().getAvatar()); %>" data-src="holder.js/64x64">
							<div class="media-body">		
						    <h4 class="media-heading"><% out.print(current.getMittente().getNome() + " " + current.getMittente().getCognome()); %></h4>	
						    </div></a><br />
					    </div>
					       	<p><strong>Ability: </strong><% out.print(current.getAbilita().getNome()); %></p>
					    	<p><strong>Sent: </strong><% out.print(current.getDataInvio()); %></p>
					    	<p><strong>Approved: </strong><% out.print(current.getDataAccettazione()); %></p>
				    </div>		     
			</div>
			<% } %>
		    <% } else { %>	
		    	<div class="alert alert-info"><strong>No received help requests:</strong> there are no approved help requests</div>
		    <% } %> 	
		</div>
		<div class="container">
			<h2>Sent Help Requests</h2>
			<h3>Pending</h3>
			<% if (areThereSentSuspendedHelpRequests) { 
				List<HelpRequests> helpRequests = (List<HelpRequests>) request.getAttribute("sentSuspendedHelpRequests");  
				for (HelpRequests current: helpRequests) { %>
				<div class="row">
					<div class="span4">
						<div class="media"><a class="pull-left" href="<% out.print("Profile?id="+ current.getMittente().getId());%>">
							<img class="media-object" alt="64x64" style="width: 64px; height: 64px;" src="<% out.print(current.getDestinatario().getAvatar()); %>"  data-src="holder.js/64x64">
							<div class="media-body">		
						    <h4 class="media-heading"><% out.print(current.getDestinatario().getNome() + " " + current.getDestinatario().getCognome()); %></h4>	
						    </div></a><br />
					    </div>
					       	<p><strong>Ability: </strong><% out.print(current.getAbilita().getNome()); %></p>
					    	<p><strong>Sent: </strong><% out.print(current.getDataInvio()); %></p>
				    </div>
				    <div class="span4">
					    <p>
						  	<a href="DeleteHelpRequest?id=<% out.print(current.getIdRichiesta()); %>"><button class="btn btn-small btn-danger" type="button">Delete</button></a>
						</p>
					</div>
			    </div>
		    <% } %>
		    <% } else { %>	
		    	<div class="alert alert-info"><strong>No sent help requests:</strong> there are no sent help requests to be approved</div>
		    <% } %>	
	    	<h3>Approved</h3>
	   		<% if (areThereSentApprovedHelpRequests) { 
				List<HelpRequests> helpRequests = (List<HelpRequests>) request.getAttribute("sentApprovedHelpRequests");  
				for (HelpRequests current: helpRequests) { %>
				<div class="row">
						<div class="span4">
						<div class="media"><a class="pull-left" href="<% out.print("Profile?id="+ current.getMittente().getId());%>">
							<img class="media-object" alt="64x64" style="width: 64px; height: 64px;" src="<% out.print(current.getDestinatario().getAvatar()); %>" data-src="holder.js/64x64">
							<div class="media-body">		
						    <h4 class="media-heading"><% out.print(current.getDestinatario().getNome() + " " + current.getDestinatario().getCognome()); %></h4>	
						    </div></a>
						</div>
					    <p><strong>Ability: </strong><% out.print(current.getAbilita().getNome()); %></p>
					    <p><strong>Sent: </strong><% out.print(current.getDataInvio()); %></p>
					    <p><strong>Approved: </strong><% out.print(current.getDataAccettazione()); %></p>
				    </div>
					<% if (!current.isCompletata()) { %>
				    <div class="span4">
					    <p>
						 	<a href="LeaveFeedback?id=<% out.print(current.getIdRichiesta()); %>"><button class="btn btn-small" type="button">Leave a Feedback</button></a>
						</p>
					</div>					
					<div class="span4">
					    <p>
						 	<a href="DeleteHelpRequest?id=<% out.print(current.getIdRichiesta()); %>"><button class="btn btn-small btn-danger" type="button">Delete</button></a>
						</p>
					</div>	
		   			<% } %>
		  	</div>
		    <% } %>
		    <% } else { %>	
		    	<div class="alert alert-info"><strong>No sent help requests:</strong> there are no approved help requests</div>
		    <% } %> 			
		</div>
	<% } %> 
	</div>
</body>
</html>